
/*
This file is part of MJIN2.

Copyright (C) 2012-2013 Opensource Game Studio

This software is provided 'as-is', without any express or implied
warranty.  In no event will the authors be held liable for any damages
arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not
   claim that you wrote the original software. If you use this software
   in a product, an acknowledgment in the product documentation would be
   appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
   misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/

#ifndef MJIN2_SOUND_SOURCE_BACKGROUND_H
#define MJIN2_SOUND_SOURCE_BACKGROUND_H

#include <mjin2/SoundSourceStream.h>
#include <mjin2/SoundTypes.h>
#include <mjin2/TypeDefs.h>

namespace mjin2
{

class SoundSourceStream;

//! Source that plays shuffled list of sound files.
class SoundSourceBackground : public SoundSourceStream::Listener
{
    public:
        SoundSourceBackground() throw ();
        ~SoundSourceBackground() throw ();

        bool isEnabled() const throw ();
        void setActiveSound(const String &name) throw (Exception);
        void setEnabled(bool state) throw (Exception);
        //! \param list List of files
        void setSounds(const StringList &list) throw (Exception);
        void setState(SOUND_SOURCE_STATE state) throw (Exception);
        void setVolume(float value) throw (Exception);
        SOUND_SOURCE_STATE state() const throw (Exception);
        float volume() const throw (Exception);

    private:
        void onSoundSourceStateChanged(SOUND_SOURCE_STATE stateSource) throw (Exception);
        void play() throw (Exception);
        // Prepare the shuffled array if necessary.
        void prepare() throw ();

        SoundSourceStream *mSource;
        StringList mSounds;
        //! Shuffled array of sounds to play.
        StringList mSoundsToPlay;
        typedef StringList::iterator SLIt;
        bool mEnabled;
        SOUND_SOURCE_STATE mState;
};

} // namespace mjin2

#endif // MJIN2_SOUND_SOURCE_BACKGROUND_H

